package com.aitou.mrylive.util;

import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.aitou.mrylive.R;


public class ReplyPopupWindow extends PopupWindow {
	private EditText input_edt;
	TextView btn_send;
	ImageView emoji;
	private View cameraMenuView;

	@SuppressWarnings("deprecation")
	public ReplyPopupWindow(Activity context, OnClickListener itemOnclick) {
		super(context);
		LayoutInflater layoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		cameraMenuView = layoutInflater.inflate(R.layout.popup_reply,
				null);

		input_edt = (EditText) cameraMenuView.findViewById(R.id.input_edit);
		btn_send = (TextView) cameraMenuView.findViewById(R.id.btn_send);
		emoji = (ImageView) cameraMenuView.findViewById(R.id.emoji);
		emoji.setOnClickListener(itemOnclick);
		btn_send.setOnClickListener(itemOnclick);
		this.setContentView(cameraMenuView);
		this.setWidth(LayoutParams.MATCH_PARENT);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
//		//设置弹出窗体需要软键盘
//		this.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
//		//设置模式，和Activity的一样，覆盖，调整大小。
//		this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//		this.setAnimationStyle(R.style.AnimBottom);
		ColorDrawable dw = new ColorDrawable(0xb000000);
		this.setBackgroundDrawable(dw);
		cameraMenuView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int height = cameraMenuView.findViewById(R.id.camera_layout)
						.getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						dismiss();
					}
				}

				return true;
			}
		});
	}
}
